package cn.edu.xjtu.nbrash.xbarsuite.zxingdemo;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.google.zxing.client.android.Intents;

import cn.edu.xjtu.nbrash.xbarsuite.R;
import cn.edu.xjtu.nbrash.xbarsuite.RashIntents;
import cn.edu.xjtu.nbrash.xbarsuite.capture.CaptureActivity;

public class RashScanActivity extends Activity {

	private static final int RASH_REQUEST_CODE = 1111;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_rash_scan);
	}

	public void doRashScan(View v) {
		// 一个非常粗糙的扫描调用
		// TODO : 使用自定义的Capture来扫描
		Intent intent = new Intent(this, CaptureActivity.class);
		// intent.setAction(Intents.Scan.ACTION);
		intent.setAction(RashIntents.Scan.ACTION_PRE_SMS);
		startActivityForResult(intent, RASH_REQUEST_CODE);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (resultCode == RESULT_OK) {
			if (requestCode == RASH_REQUEST_CODE) {
				if (data != null) {
					String result = data.getStringExtra(Intents.Scan.RESULT);
					new AlertDialog.Builder(this).setTitle("扫描结果为：")
							.setMessage(result).show();
				}
			}
		}
	}

}
